
cd "/Users/chuangchen/Library/CloudStorage/OneDrive-UniversityofPittsburgh/LASA/Datos"

use "all_countries2.dta", clear
rename legis year

nearmrg pais using "LAPOP_pid.dta", nearvar(year) genmatch(usingmatch)


keep if _merge==3
drop usingmatch _merge

nearmrg pais using "LAPOP_crime.dta", nearvar(year) genmatch(usingmatch)
keep if _merge==3
drop usingmatch _merge

rename year legis

est clear

*******************************************
* Interaction with time. 
gen time = .
replace time = 1 if legis>2009
replace time = 0 if legis<2010
label variable time "Post 2009"


gen wave2=(wave>2)

* Create a single variable with values based on conditions
gen new_variable = .

replace new_variable = 1 if eco_moral2 == 7
replace new_variable = 2 if eco_moral2 == 8
replace new_variable = 3 if eco_moral2 == 4
replace new_variable = 4 if eco_moral2 == 6
replace new_variable = 5 if eco_moral2 == 3

* Label the values of the new variable
label define new_var_labels2 1 "MpEc" 2 "MpEm" 3 "MmEc" 4 "MmEp" 5 "McEp"
label values new_variable new_var_labels2


/// Dummy per each combinations
gen McEc=(eco_moral2==1)
gen McEm=(eco_moral2==2)
gen MmEm=(eco_moral2==5)
gen MpEp=(eco_moral2==9)


gen MpEc=(eco_moral2==7)
gen MpEm=(eco_moral2==8)
gen MmEc=(eco_moral2==4)
gen MmEp=(eco_moral2==6)
gen McEp=(eco_moral2==3)

bysort pais: cor eco_moral2 time
* Bolivia (-0.2897), El Salvador (0.2009), Nicaragua (-0.2257), Paraguay (-0.2890) are >0.2

save"all_countries3.dta", replace
***************************************
